layui.use(['form', 'table','layuimini','element'], function () {
    var $ = layui.jquery,
        form = layui.form,
        table = layui.table,
        layuimini = layui.layuimini;

    /**
     * 初始化表单，要加上，不然刷新部分组件可能会不加载
     */
    form.render();

    var BoMsgSign = {
        id: 'BoMsgSignTable'
    };

    // 当前弹出层，防止ID被覆盖
    var parentIndex = layer.index;

    var column = [
        [
            {type: 'radio'},
            {field: 'signName', title: '签名名称', align: 'center'},
            {field: 'signCode', title: '工单号', align: 'center'},
            {field: 'remark', title: '备注', align: 'center',
                templet: function (object) {
                    if(object.remark == '' || object.remark == undefined || object.remark == null){
                        return '-';
                    }else{
                        return object.remark;
                    }
                }
            },
            {field: 'updateDate', title: '更新时间', minWidth: 120, align: 'center'},
            {field: 'createDate', title: '创建时间', minWidth: 120, align: 'center'}
        ]
    ];

    table.render({
        elem: '#' + BoMsgSign.id,
        url: '/web/boMsgSign/list',
        toolbar: '#in_toolbarBtn',
        defaultToolbar: [],
        cols: column,
        limits: [10, 15, 20, 25, 50, 100],
        limit: 15,
        page: true
    });

    // 监听搜索操作
    $("#in_data-search-btn").on('click', function () {

        //获取搜索条件
        var signName = $("#in_search_signName").val();

        //封装
        var dataObject = {};
        dataObject['signName'] = signName;
        var result = JSON.stringify(dataObject);

        //执行搜索重载
        table.reload(BoMsgSign.id, {
            page: {
                curr: 1
            }
            , where: {
                searchParams: result
            }
        }, 'data');

        return false;
    });

    // 监听重置操作
    $("#in_data-reset-btn").on('click', function () {

        //初始化
        $("#in_search_signName").val("");

        form.render();

        //封装
        var dataObject = {};
        dataObject['signName'] = "";
        var result = JSON.stringify(dataObject);

        //执行搜索重载
        table.reload(BoMsgSign.id, {
            page: {
                curr: 1
            }
            , where: {
                searchParams: result
            }
        }, 'data');

        return false;
    });


    // 监听确定选择操作
    $(".layuimini-container").on("click", "#in_choose-btn", function () {
        var msgSignId = $("#in_msgSignId").val();
        var msgSignName = $("#in_msgSignName").val();
        $("#msgSignId").val(msgSignId);
        $("#msgSignName").val(msgSignName);
        // 关闭弹出层
        layer.close(parentIndex);
        return true;
    });


    //监听表格单选按钮
    table.on('radio(BoMsgSignTable)', function (obj) {
        $("#in_msgSignId").val(obj.data.id);
        $("#in_msgSignName").val(obj.data.signName);
    });

});